
import { defineStore } from 'pinia'
import { ref } from 'vue'

import {User} from '@/views/type'


 const useUserStore =defineStore('user',()=>{

    const token =ref<string>()
    const user = ref<User>({
        id: 0,
        name: " ",
        loginName: " ",
        password: "",
        token: "",
      });
    const setToken =(newToken:string)=>{
        token.value =newToken
    }
    const removeToken =()=>{
        token.value= ""
    }
    const setUser = (newUser:User)=>{
        user.value =newUser
        console.log(user.value)
    }
    const removeUser=() =>{
        user.value={id: 0,
            name: " ",
            loginName: " ",
            password: "",
            token: "",}
    }

    return { token, setToken, removeToken, setUser,removeUser,user}; 

},{persist:true})

export default useUserStore ;